<template>
	<view class="mainpadding2">
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
		</view>
		<view class="ffffff mainpadding margin_top radius" v-else v-for="item in list.data" :key="item.id" @click="selectrole(item.id)">
			<view class="flexleft">
				<view class="sanshier margin_right1 xiaohei">{{item.name}}</view>
				<view class="sanshier xiaohei">{{item.mobile}}</view>
			</view>
			<view class="margin_top2 flexleft xiahuaxian">
				<view class="margin_right1">
					<u-icon name="map-fill" color="#2979ff" size="28"></u-icon>
				</view>
				<view class="sanshier xiaohei">{{item.cityinfo}}{{item.address_detail}}</view>
			</view>
			<view class="flexbetween margin_top2">
				<view class="flexleft" @click.stop="moren(item.id)">
					<!-- 已勾选 -->
					<view class=" margin_right1" v-if="item.status==1">
						<u-icon name="checkmark-circle-fill" color="#2979ff" size="22"></u-icon>
					</view>
					<!-- 未勾选 -->
					<view class="weigx margin_right1"  v-if="item.status!=1"></view>
					<view class="nostrongtext">{{item.status==1?"默认地址":"设为默认"}}</view>
				</view>
				<view class="flexright">
					<view class="flexright margin_right1" @click.stop="bjdz(item.id)">
						<u-icon name="edit-pen" size="24"></u-icon>
						<view class="nostrongtext">编辑</view>
					</view>
					<view class="flexright "  @click.stop="deladdress(item.id)">
						<u-icon name="trash" size="24"></u-icon>
						<view class="nostrongtext">删除</view>
					</view>
				</view>
				
			</view>

		</view>
		<view class="gudingdb  mainpadding" @click="tzxzdz">
			<view class="bigbtn">+新增收货地址</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: "",
				page: 1,
				list: {
					data: []
				},
			}
		},
		onLoad(options) {
			this.type = options.type
		},
		onShow() {
			this.init();
		},
		methods: {
			deladdress(id) {
				httpRequest.modal('提示', '确认删除当前数据吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/deladdress', 'GET', {
							id
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			selectrole(id){
				if(this.type==1){
					uni.$emit("checkaddress",id)
					uni.navigateBack(1)
				}
			},
			moren(id){
				httpRequest.request("/api/user/setAddressMr", 'GET', {
					id,
					status:1
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if(res.code==1){
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			init() {
				let _this = this;
				httpRequest.request("/api/user/addressList", 'GET', {
				}, false, false, true).then(res => {
					this.list.data = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			bjdz(id) {
				uni.navigateTo({
					url: '/pages/mypage/xinzengshdz?id='+id
				})
			},
			// 跳转新增收货地址
			tzxzdz() {
				uni.navigateTo({
					url: '/pages/mypage/xinzengshdz'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.weigx {
		width: 32rpx;
		height: 32rpx;
		border-radius: 50%;
		border: 2rpx solid #000000;
		background-size: 100% 100%;
	}
	.shanchu1s {
		width: 33rpx;
		height: 33rpx;
		background-size: 100% 100%;
		background-image: url('@/static/image/sysem/shanchu.png');
	}

	.xiahuaxian {
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	// .dizhiicon {
	// 	width: 26rpx;
	// 	height: 31rpx;
	// 	background-size: 100% 100%;
	// 	background-image: url('../../static/image/system/dizhi1.png');
	// }
</style>